package me.zhengjie.modules.management.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.management.mapper.ConferenceRecordMapper;
import me.zhengjie.modules.management.mapper.OaStatusMapper;
import me.zhengjie.modules.management.service.dto.RecordDto;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @website https://docs.auauz.net
 * @Description:
 * @Auther: chao.ji
 * @Date: 2020/12/30
 */
@Component
@RequiredArgsConstructor
public class OaStatusJob extends IJobHandler {

    private final ConferenceRecordMapper conferenceRecordMapper;

    private final OaStatusMapper oaStatusMapper;


    @XxlJob("mr-oa")
    @Override
    public ReturnT<String> execute(String s) throws Exception {
         //获取会议状态是审批中的会议
         List<RecordDto> list=conferenceRecordMapper.findRecord();
         for (RecordDto recordDto : list) {
             //通过id找到requestId
             Integer requestId=conferenceRecordMapper.findRequestId(recordDto.getRecordId());
             //OA找到状态,判断状态
             String hahaha=oaStatusMapper.getStatus(requestId);
             switch(oaStatusMapper.getStatus(requestId)){
                 //审批通过
                 case "0":
                     if(recordDto.getStatus()==2){
                         recordDto.setStatus(3);
                         conferenceRecordMapper.updateRecordById(recordDto);
                     }
                     break;
                 //退回
                 case "1":
                     /*conferenceRecordMapper.deleteRecord(recordDto.getRecordId());*/
                     recordDto.setStatus(8);
                     /*recordDto.setModifyUserId(SecurityUtils.getCurrentUsername());*/
                     recordDto.setModifyDateTime(new Timestamp(new Date().getTime()));
                     conferenceRecordMapper.updateRecordById(recordDto);
                     break;
                 //审批中
                 case "2":
                     break;
             }
         }
        return ReturnT.SUCCESS;
    }


}
